/*
 * =====================================================================================
 *
 *       Filename:  alarm_clock.h
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  10/03/2010 03:27:13 PM
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Ken Chen (Ziliang), zlchen.ken@gmail.com
 *        Company:  EMC
 *
 * =====================================================================================
 */

#ifndef _ALARM_CLOCK_H
#define _ALARM_CLOCK_H

#include <list>
#include <boost/shared_ptr.hpp>
#include "cl_lock.h"
#include "cl_timer.h"

class AlarmClock
{
public:
	AlarmClock();
	void registerAlarmListener( AlarmListener* listener, int interval, bool isRepeated );

private:
	AlarmClock( const AlarmClock& );
	AlarmClock& operator=( const AlarmClock& );

	void elapse( void );
	struct AlarmListenerData
	{
		AlarmListenerData( AlarmListener* listener, int interval, bool repeated )
			: itsListener(listener), itsInterval(interval), 
			itsTimer(new CLTimer(interval)), isRepeated(repeated)
		{
		}
		// AlarmListenerData is not responsible for freeing 
		// AlarmListener's resource.
	  AlarmListener* itsListener;
		boost::shared_ptr<CLTimer> itsTimer;
		bool isRepeated;
	};

  std::list<AlarmListenerData*> itsAlarmListeners;
	boost::shared_ptr<CLLock> itsLock;
	
	friend class TimeIntervalComp;
};

#endif //_ALARM_CLOCK_H
